/**
@Description  请填写文件描述（需要改）
@author: freedom
@date: 2021/5/13
@note:
**/
package utils

import (
	"gin-vue-admin/model/request"
	"github.com/gin-gonic/gin"
	"strconv"
)

func GetUserIdByRequest(c gin.Context) int {
	var userId int
	if claims, ok := c.Get("claims"); ok {
		waitUse := claims.(*request.CustomClaims)
		userId = int(waitUse.ID)
	} else {
		id, err := strconv.Atoi(c.Request.Header.Get("x-user-id"))
		if err != nil {
			userId = 0
		}
		userId = id
	}
	return userId
}
